package com.bmps.springcloud.insuredmicroservice.callback.accept;

import com.bmps.springcloud.common.response.TaskResponseModel;
import com.bmps.springcloud.common.task.bean.RequestObject;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.AcceptRequestDataModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.ProductModel;
import com.bmps.springcloud.insuredmicroservice.service.underwrite.AcceptService;

import java.util.concurrent.Callable;

/**
 * description:
 * 计算未成年人死亡责任险保额任务
 *
 * @author jackdaw
 * @date 2019-12-27 14:41
 */
public class MinorDeathLiabilityCallBack implements Callable<TaskResponseModel> {
    private String key;
    private RequestObject requestObject;
    private final AcceptService acceptService;

    public MinorDeathLiabilityCallBack(String key, AcceptService acceptService, RequestObject requestObject) {
        this.setKey(key);
        this.acceptService = acceptService;
        this.setRequestObject(requestObject);
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    private void setRequestObject(RequestObject requestObject) {
        this.requestObject = requestObject;
    }

    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     */
    @Override
    public TaskResponseModel call() {
        return acceptService.checkMinorDeathLiability(key, (ProductModel) requestObject.getParams(), (AcceptRequestDataModel) requestObject.getAccept());
    }
}
